local zeshuai = fk.CreateSkill{
  name = "hanqing__zeshuai",
}

Fk:loadTranslationTable{
  ["hanqing__zeshuai"] = "择帅",
  [":hanqing__zeshuai"] = "游戏开始时或回合开始时，若场上没有【赵帅符】，你可以将【赵帅符】置于你的装备区；拥有【赵帅符】的角色的回合结束时，"..
  "若其本回合未造成伤害，你可以移动【赵帅符】。",

  ["#hanqing__zeshuai-invoke"] = "择帅：是否将【赵帅符】置入你的装备区？",
  ["#hanqing__zeshuai-move"] = "择帅：你可以将 %dest 的【赵帅符】移动给另一名角色",
}

local spec = {
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = zeshuai.name,
      prompt = "#hanqing__zeshuai-invoke",
    })
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local id = room:getBanner(zeshuai.name)[1]
    room:moveCardIntoEquip(player, id, zeshuai.name, false, player)
  end,
}

zeshuai:addEffect(fk.GameStart, {
  anim_type = "control",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(zeshuai.name) and
      not table.find(player.room.alive_players, function (p)
        return table.find(p:getEquipments(Card.SubtypeTreasure), function(id)
          return Fk:getCardById(id).name == "zhao_tiger_tally"
        end) ~= nil
      end) and
      player.room:getCardArea(player.room:getBanner(zeshuai.name)[1]) == Card.Void and
      player:canMoveCardIntoEquip(player.room:getBanner(zeshuai.name)[1], false)
  end,
  on_cost = spec.on_cost,
  on_use = spec.on_use,
})

zeshuai:addEffect(fk.TurnStart, {
  anim_type = "control",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(zeshuai.name) and
      not table.find(player.room.alive_players, function (p)
        return table.find(p:getEquipments(Card.SubtypeTreasure), function(id)
          return Fk:getCardById(id).name == "zhao_tiger_tally"
        end) ~= nil
      end) and
      player.room:getCardArea(player.room:getBanner(zeshuai.name)[1]) == Card.Void and
      player:canMoveCardIntoEquip(player.room:getBanner(zeshuai.name)[1], false)
  end,
  on_cost = spec.on_cost,
  on_use = spec.on_use,
})

zeshuai:addEffect(fk.TurnEnd, {
  anim_type = "control",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(zeshuai.name) and
      table.contains(target:getEquipments(Card.SubtypeTreasure), player.room:getBanner(zeshuai.name)[1]) and
      table.find(player.room:getOtherPlayers(target, false), function (p)
        return target:canMoveCardInBoardTo(p, player.room:getBanner(zeshuai.name)[1])
      end) and
      #player.room.logic:getActualDamageEvents(1, function (e)
        return e.data.from == target
      end, Player.HistoryTurn) == 0
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room:getOtherPlayers(target, false), function (p)
        return target:canMoveCardInBoardTo(p, room:getBanner(zeshuai.name)[1])
      end)
    local to = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = targets,
      skill_name = zeshuai.name,
      prompt = "#hanqing__zeshuai-move",
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, {tos = to})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    room:moveCardIntoEquip(to, room:getBanner(zeshuai.name)[1], zeshuai.name, false, player)
  end,
})

zeshuai:addAcquireEffect(function (self, player, is_start)
  local room = player.room
  if not room:getBanner(zeshuai.name) then
    room:setBanner(zeshuai.name, {room:printCard("zhao_tiger_tally", Card.Spade, 8).id})
  end
end)

return zeshuai
